package com.example.healthcondition.services.impl;

import com.example.healthcondition.entity.ExerciseRecords;
import com.example.healthcondition.mapper.ExerciseMapper;
import com.example.healthcondition.services.ExerciseService;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.Map;

@Service
public class ExerciseServiceImpl implements ExerciseService {
    private final ExerciseMapper exerciseMapper;

    public ExerciseServiceImpl(ExerciseMapper exerciseMapper) {
        this.exerciseMapper = exerciseMapper;
    }

    @Override
    public Map<String, Object> addExercise(ExerciseRecords exerciseRecord) {
        Map<String, Object> result = new HashMap<>();
        int count = exerciseMapper.insert(exerciseRecord);
        if (count >= 1) {
            result.put("message", "添加成功");
            result.put("flag", true);
            result.put("count", count);
        } else {
            result.put("message", "添加失败");
            result.put("flag", false);
            result.put("count", count);
        }
        return result;
    }

    @Override
    public Map<String, Object> updateExercise(ExerciseRecords exerciseRecord) {
        Map<String, Object> result = new HashMap<>();
        int count = exerciseMapper.update(exerciseRecord);
        if (count >= 1) {
            result.put("message", "更新成功");
            result.put("code", 0);
            result.put("flag", true);
            result.put("count", count);
        } else {
            result.put("message", "更新失败");
            result.put("code", 1);
            result.put("flag", false);
            result.put("count", count);
        }
        return result;
    }

    @Override
    public Map<String, Object> deleteExercise(Integer recordId) {
        Map<String, Object> result = new HashMap<>();
        int count = exerciseMapper.delete(recordId);
        if (count >= 1) {
            result.put("message", "删除成功");
            result.put("flag", true);
            result.put("count", count);
        } else {
            result.put("message", "删除失败");
            result.put("flag", false);
            result.put("count", count);
        }
        return result;
    }
}

